package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Topic;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.TopicService;
import com.chunfeng.mypen.vo.TopicVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 题目控制层
 * @author: 小雷
 * @createTime: 2023-11-14 00:24:45
 */
@Slf4j
@RestController
@RequestMapping("/topic")
@Api(value = "题目控制层", tags = "题目访问操作接口")
public class TopicController {
    @Autowired
    private TopicService topicService;

    /**
     * 条件查询所有题目
     *
     * @param topic 题目实体类，包含所有查询条件
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选题目信息")
    public JsonRequest<List<TopicVo>> lookTopic(@ApiParam(value = "题目信息", required = true)
                                                @RequestParam(name = "topic") Topic topic) {
        return topicService.lookTopic(topic);
    }

    /**
     * 新增题目
     *
     * @param topic 题目实体类
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增题目信息")
    public JsonRequest<Integer> addTopic(@ApiParam(value = "题目信息", required = true)
                                         @RequestBody Topic topic) {
        return topicService.addTopic(topic);
    }

    /**
     * 修改题目
     *
     * @param topic 需要修改的实体类
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改题目信息")
    public JsonRequest<Integer> updateTopic(@ApiParam(value = "修改的题目信息", required = true)
                                            @RequestBody Topic topic) {
        return topicService.updateTopic(topic);
    }

    /**
     * 删除题目
     *
     * @param ids 需要删除的题目id
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "删除题目")
    public JsonRequest<Integer> deleteTopic(@ApiParam(value = "删除题目的id", required = true)
                                            @RequestBody List<String> ids) {
        return topicService.deleteTopic(ids);
    }
}
